package com.mvp.shq.washer.ui.mine;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.mvp.shq.washer.R;
import com.mvp.shq.washer.base.BaseFragment;
import com.mvp.shq.washer.entity.User;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.rxbus.Subscribe;
import com.mvp.shq.washer.utils.EventCode;
import com.mvp.shq.washer.utils.JumpUtil;
import com.mvp.shq.washer.utils.SpUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * A simple {@link Fragment} subclass.
 */
public class MineFragment extends BaseFragment<MinePresenter, MineModel> implements MineConstract.View {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_username)
    TextView tvUsername;
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.img_user)
    ImageView imgUser;
    private User user;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    public void initView() {
        back.setVisibility(View.GONE);
        setUserInfo();
    }

    @OnClick({R.id.tv_username,R.id.all_wallet, R.id.all_coupon, R.id.all_msg, R.id.all_setting, R.id.all_share, R.id.all_link,R.id.arl_userinfo})
    public void onViewClicked(View view) {
        if (user == null){
            JumpUtil.toLogin(context);
            RxBus.get().send(EventCode.LOGIN_OUT);
            return;
        }
        switch (view.getId()) {
            case R.id.tv_username:
                break;
            case R.id.all_wallet:
                JumpUtil.toWallet(context);
                break;
            case R.id.all_coupon:
                break;
            case R.id.all_msg:
                JumpUtil.toNews(context);
                break;
            case R.id.all_setting:
                JumpUtil.toSetting(context);
                break;
            case R.id.all_share:
                JumpUtil.toShare(context);
                break;
            case R.id.all_link:
                JumpUtil.toContactUs(context);
                 break;
            case R.id.arl_userinfo:
                JumpUtil.toUserCenter(context);
                break;
        }
    }
    @Subscribe(code = EventCode.UPDATE_USER)
    public void setUserInfo(){
        user = SpUtil.getUser();
        if (user == null){
            tvUsername.setText("点击登录");
            tvBalance.setText("秒速登录，体验更多功能");
            return;
        }
        imageUtil.loadCircleImage(user.getFaceurl(),imgUser);
        if (!TextUtils.isEmpty(user.getNickname())){
            tvUsername.setText(user.getNickname());
        }else if (!TextUtils.isEmpty(user.getMobile())){
            tvUsername.setText(user.getNickname());
        }
        if (user.getRechargeBalance() != null){
            tvBalance.setText(user.getRechargeBalance()+"元");
        }
    }
}
